<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<table class="fwin" cellspacing="0" cellpadding="0">
	<tbody>
		<tr>
			<td class="t_l"></td>
			<td class="t_c"></td>
			<td class="t_r"></td>
		</tr>
		<tr>
			<td class="m_l"></td>
			<td class="m_c">
				<div class="f_c">
					<div id="topic_tools" class="c">
						<textarea id="editortext_dialog" name="editor_dialog" rows="10"
							style="width: 99.4%;"></textarea>
					</div>
				</div>
			</td>
			<td class="m_r"></td>
		</tr>
		<tr>
			<td class="b_l"></td>
			<td class="b_c"></td>
			<td class="b_r"></td>
		</tr>
	</tbody>
</table>
<script type="text/javascript" >
$(function (){
	$("#editortext_dialog").xheditor(
			{
				plugins : getCodePlugin(),
				tools : "Cut,Copy,Paste,Pastetext,|,Blocktag,Fontface,FontSize,Bold,Italic,Underline,Strikethrough,FontColor,BackColor,Removeformat,|,Align,List,Outdent,Indent,|,Link,Unlink,Img,Emot,Table,Code,|,Source,Fullscreen",
				upImgUrl : "!../learning/uploadimg.jsp",
				loadCSS : "../css/editor.css"
			});
});

function getCodePlugin() {
	var codeArr1 = [ "html", "objc", "javascript", "css", "php", "csharp",
			"cpp", "java", "python", "ruby", "vb", "delphi", "sql", "plain" ];
	var codeArr2 = [ "HTML/XML", "Objective-C", "JavaScript", "CSS", "PHP",
			"C#", "C++", "Java", "Python", "Ruby", "Visual Basic",
			"Delphi", "SQL", "其它" ];
	var opts = '';
	for (var i = 0; i < codeArr1.length; i++) {
		opts += csdn.format('<option value="{0}">{1}</option>',
				codeArr1[i], codeArr2[i]);
	}
	var htmlCode = '<div>编程语言: <select id="xheCodeType">'
			+ opts
			+ '</select></div>'
			+ '<div><textarea id="xheCodeCon" rows=6 cols=40></textarea></div>'
			+ '<div style="text-align:right;"><input type="button" id="xheSave" value="确定" /></div>';
	var htmlSCode = '<div><textarea id="xheSCodeCon" rows=6 cols=40></textarea></div>'
			+ '<div style="text-align:right;"><a href="https://code.csdn.net/help/CSDN_Code/code_support/FAQ_6_1" style="float:left;" target=_blank>什么是CODE代码片？</a><input type="button" id="xheSSave" value="确定" /></div>';

	var codePlugin = {
		Code : {
			c : 'Code',
			t : '插入代码',
			h : 1,
			e : function() {
				var _this = this;
				var jTest = $(htmlCode);
				var jSave = $('#xheSave', jTest);
				jSave.click(function() {
					var sel_code = $("#xheCodeType").val();
					//var str = csdn.format('<pre name="code" class="{0}">{1}</pre><br />', sel_code, _this.domEncode($("#xheCodeCon").val()));
					var xheCodeConContent = $("#xheCodeCon").val() + "";
					xheCodeConContent = xheCodeConContent.replace(/&reg/g,
							"&amp;reg").replace(/&copy/g, "&amp;copy");

					var str = '<pre name="code" class="' + sel_code + '">'
							+ _this.domEncode(xheCodeConContent)
							+ '</pre><br />';
					_this.loadBookmark();
					_this.pasteHTML(str);
					_this.hidePanel();
					document.cookie = "postedit_code=" + sel_code
							+ "; expires=" + function() {
								var d = new Date();
								d.setFullYear(d.getFullYear() + 1);
								return d.toGMTString();
							}();
					return false;
				});
				_this.saveBookmark();
				_this.showDialog(jTest);
				var _his_code = document.cookie.match(new RegExp(
						"(^|\s)postedit_code=([^;]*)(;|$)"));
				if (_his_code)
					$('#xheCodeType').val(_his_code);
				else
					$("#xheCodeType option")[0].selected = true;
			}
		},
		SCode : {
			c : 'SCode',
			t : '引用CODE代码片',
			h : 1,
			e : function() {
				var _this = this;
				var jTest = $(htmlSCode);
				var jSave = $('#xheSSave', jTest);
				jSave.click(function() {
					var str = $("#xheSCodeCon").val();
					var cid = 0;
					var mat = new RegExp('/([a-z0-9]+).js', 'i').exec(str);
					if (mat) {
						cid = mat[1];
					} else if (/^[a-z0-9]+$/i.test(str)) {
						cid = str;
					}
					if (cid) {
						str = '<div>{CSDN:CODE:' + cid + '}</div>';
						_this.loadBookmark();
						_this.pasteHTML(str);
					}
					_this.hidePanel();
					return false;
				});
				_this.saveBookmark();
				_this.showDialog(jTest);
			}
		}
	};
	return codePlugin;
}
</script>